package com.eonmind.vip.util;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class TimeUtil {

    public static Long timeMinusMillis(int days, Long currentTimeMillis) {
        if (currentTimeMillis == null) {
            throw new IllegalArgumentException("当前时间不能为null");
        }

        return Instant.ofEpochMilli(currentTimeMillis)
                .plus(days, ChronoUnit.DAYS)
                .toEpochMilli();
    }

    public static Boolean isBeforeCurrentTime(Long current, Long time) {
        // 参数校验
        if (current == null || time == null) {
            throw new IllegalArgumentException("时间参数不能为null");
        }

        // 比较时间戳
        return time < current;
    }

    public static String LongToString(Long time) {
        // 创建一个SimpleDateFormat对象，用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 将Long类型的时间戳转换为Date对象
        Date date = new Date(time);
        // 使用SimpleDateFormat格式化Date对象为字符串
        return sdf.format(date);
    }
}
